package com.example.scenictourback.dto;

import com.example.scenictourback.entity.Hotel;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public class HotelDTO {
    
    private Integer id;
    private String name;
    private String address;
    private String phone;
    private Integer scenicAreaId;
    private String scenicAreaName;
    
    // 扩展字段，用于展示酒店房间列表
    private List<RoomDTO> rooms;
    
    // 静态方法，将实体对象转为DTO对象
    public static HotelDTO fromEntity(Hotel hotel) {
        HotelDTO dto = new HotelDTO();
        dto.setId(hotel.getId());
        dto.setName(hotel.getName());
        dto.setAddress(hotel.getAddress());
        dto.setPhone(hotel.getPhone());
        
        if (hotel.getScenicArea() != null) {
            dto.setScenicAreaId(hotel.getScenicArea().getId());
            dto.setScenicAreaName(hotel.getScenicArea().getName());
        }
        
        return dto;
    }
    
    // 静态方法，将实体列表转为DTO列表
    public static List<HotelDTO> fromEntities(List<Hotel> hotels) {
        return hotels.stream()
                .map(HotelDTO::fromEntity)
                .collect(Collectors.toList());
    }
} 